package com.ruoyi.web.controller.position;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.control.dto.RYJZDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.position.domain.Ryjz;
import com.ruoyi.position.service.IRyjzService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员定位-进入限制区域告警Controller
 *
 * @author hcc
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/control/ryjz")
public class RyjzController extends BaseController
{
    @Autowired
    private IRyjzService ryjzService;

    /**
     * 查询人员定位-进入限制区域告警列表
     */
    //@PreAuthorize("@ss.hasPermi('control:ryjz:list')")
    @GetMapping("/list")
    @ApiOperation("人员基站信息")
    public TableDataInfo list(Ryjz ryjz)
    {
        startPage();
        List<Ryjz> list = ryjzService.selectRyjzList(ryjz);
        return getDataTable(list);
    }
    /**
     * 查询人员定位-进入限制区域告警列表
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:list')")
    @GetMapping("/listArr")
    public List<RYJZDto> listArr(Ryjz ryjz)
    {
        List<Ryjz> list = ryjzService.selectRyjzList(ryjz);
        List<RYJZDto> listDto =list.stream().map(item ->{
            RYJZDto ryjzDto=new RYJZDto();
            BeanUtils.copyProperties(item,ryjzDto);
            List<Ryjz> ryjzList= ryjzService.selectRyjzNum(item);
            ryjzDto.setNum(String.valueOf(ryjzList.size()));
            return ryjzDto;
        }).collect(Collectors.toList());
        return listDto;
    }
    /**
     * 导出人员定位-进入限制区域告警列表
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:export')")
    @Log(title = "人员定位-进入限制区域告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ryjz ryjz)
    {
        List<Ryjz> list = ryjzService.selectRyjzList(ryjz);
        ExcelUtil<Ryjz> util = new ExcelUtil<Ryjz>(Ryjz.class);
        util.exportExcel(response, list, "人员定位-进入限制区域告警数据");
    }

    /**
     * 获取人员定位-进入限制区域告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:query')")
    @GetMapping(value = "/{baseStationId}")
    public AjaxResult getInfo(@PathVariable("baseStationId") String baseStationId)
    {
        return success(ryjzService.selectRyjzByBaseStationId(baseStationId));
    }

    /**
     * 新增人员定位-进入限制区域告警
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:add')")
    @Log(title = "人员定位-进入限制区域告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ryjz ryjz)
    {
        return toAjax(ryjzService.insertRyjz(ryjz));
    }

    /**
     * 修改人员定位-进入限制区域告警
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:edit')")
    @Log(title = "人员定位-进入限制区域告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ryjz ryjz)
    {
        return toAjax(ryjzService.updateRyjz(ryjz));
    }

    /**
     * 删除人员定位-进入限制区域告警
     */
    @PreAuthorize("@ss.hasPermi('control:ryjz:remove')")
    @Log(title = "人员定位-进入限制区域告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseStationIds}")
    public AjaxResult remove(@PathVariable String[] baseStationIds)
    {
        return toAjax(ryjzService.deleteRyjzByBaseStationIds(baseStationIds));
    }
}
